package com.treasure.hunt.api

import com.module.lemlin.mode.SubscribeListener
import com.module.lemlin.rxhttp.HttpServiceData
import com.treasure.hunt.api.subscribe.subscribe
import com.treasure.hunt.entity.UserInfoResponse
import io.reactivex.rxjava3.disposables.Disposable
import rxhttp.RxHttp


/**
 * 微信登录
 * */
fun userLogin(
    deviceNumber: String,
    parentId: Int = 0,
    type: Int = 0,
    listener: SubscribeListener<HttpServiceData>
): Disposable = subscribe(
    RxHttp.postForm("/api/user/third")
        //.setAssemblyEnabled(false)
        .add("device_number", deviceNumber)
        .add("parent_id", parentId)
        .add("type", type)
        .asClass(HttpServiceData::class.java)
    , listener
)


/**
 * 获取用户信息
 * */
fun userInfo(
    listener: SubscribeListener<UserInfoResponse>
): Disposable = subscribe(
    RxHttp.postForm("/api/user/get_user_info")
        .asClass(UserInfoResponse::class.java)
    , listener
)

/**
 * 微信登录
 * */
fun userThird(
    code: String, listener: SubscribeListener<HttpServiceData>
): Disposable = subscribe(
    RxHttp.get("/api/user/third")
        .add("code", code)
        .asClass(HttpServiceData::class.java)
    , listener
)

/**
 * 修改个人信息
 * */
fun userProfile(
    nickname: String, listener: SubscribeListener<HttpServiceData>
): Disposable =
    subscribe(
        RxHttp.get("/api/user/profile")
            .add("nickname", nickname)
            .asClass(HttpServiceData::class.java)
        , listener
    )